package com.sky.mapper;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

@SuppressWarnings("all")
@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 添加新员工
     * @param employee
     */

    @Insert("INSERT INTO `employee` VALUES (null,#{name},#{username}, MD5(password),#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser});")
    void insert(Employee employee);

    /**
     * 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    List<Employee> pageSelectEmp(String name);


    /**
     * 根据id  查找员工的密码
     * @param empId
     * @return
     */
    @Select("select   password from employee where id =#{empId}")
       String selectEmpPassword( Long empId);
    /**
     * 修改员工密码
     * @param passwordEditDTO
     */
    @Update("update  employee  set  password =MD5(#{newPassword}) where id =#{empId};")
    void updateEmpPassword(PasswordEditDTO passwordEditDTO);

    /**
     * 根据id 查询员工
     * @param inD
     * @return
     */
//    @Options(keyProperty = "id" ,useGeneratedKeys = true)
    @Select("select * from employee where id =#{inD}")
    Employee selectEmpById(Integer inD);

    /**
     * 修改员工信息
     * @param employee
     */
    void updateEmp(Employee employee);

    /**
     *  启动  / 禁止
     * @param employee
     */
    @Update("update  employee  set  status  =#{status}  where id =#{id}")
    void updateEmpStatus(Integer status, Long id);

}
